package com.smartalarmclock.Model;


import com.smartalarmclock.Model.Exceptions.DataEntityDoesNotExistException;
import com.smartalarmclock.Model.Exceptions.InvalidDeleteDataEntityOperationException;
import com.smartalarmclock.Model.Exceptions.InvalidSaveDataEntityOperationException;

import android.content.Context;

/**
 * All data entities must implement this interface. It contains
 * basic database functionality on the instance such as insert, update and delete. 
 *  @param <T> the concrete data entity class
 */
public interface IDataEntity extends Comparable<IDataEntity>{
	
	/**
	 * @return the data entity's id.
	 */
	public int GetId();
	
	/**
	 * Loads all members again from the DB and updates the object in memory with the current values.
	 * The loading process uses the object's id.
	 * @param context the context of the request
	 * @throws DataEntityDoesNotExistException if the entity with the current id does not exist in the DB,
	 * or if the object was not yet saved in the DB.
	 */
	public void Refresh(Context context) throws DataEntityDoesNotExistException;
	
	/**
	 * Saves the instance in the database.
	 * @param context the context of the request
	 * @throws InvalidSaveDataEntityOperationException if values are invalid
	 */
	public void Save(Context context) throws InvalidSaveDataEntityOperationException;
	
	/**
	 * Deletes the instance from the database
	 * @param context the context of the request
	 * @throws InvalidDeleteDataEntityOperationException if the data entity is referenced and cannot be deleted
	 * @throws InvalidSaveDataEntityOperationException if the referencing data entity's save operation was invalid.
	 */
	public void Delete(Context context) throws InvalidDeleteDataEntityOperationException, InvalidSaveDataEntityOperationException;
}
